package com.yanqu.road.server.logic.task;

import com.yanqu.road.entity.autodata.task.UserObjectTaskData;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.logic.task.objectcondition.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ObjectTaskConditionFactory {
    private static Map<Integer, Class<? extends BaseObjectCondition>> classMap = new HashMap<>();

    static {
        classMap.put(eGamePlayerEventType.TargetCricketUpTitle.getValue(), CricketUpTitleObjectCondition.class);
    }

    public static Map<Integer, Class<? extends BaseObjectCondition>> getClassMap() {
        return classMap;
    }

    public static BaseObjectCondition createCondition(GamePlayer player, int completeType, List<Integer> taskIds, Map<Integer, UserObjectTaskData> taskDataMap) throws InstantiationException, IllegalAccessException {
        Class<? extends BaseObjectCondition> aClass = classMap.get(completeType);
        if (aClass == null) {
            return null;
        }
        //调用BaseObjectCondition的构造函数
        BaseObjectCondition baseObjectCondition = aClass.newInstance();
        baseObjectCondition.init(completeType, player, taskIds, taskDataMap);
        return baseObjectCondition;
    }
}
